<template>
  <!-- 页脚操作栏 -->
  <div class="btn_box tool-btns--fixed page-btn-right-top">
    <BasePrintButton v-if="needPrint" :beforePrintFn="() => getPritContent()" class="button_right" />
    <a-button :loading="loading['submitDraft']" :disabled="loading['submitDraft']" v-if="editModel != '2' && !onlySubmit" type="primary" class="button_right" @click="handleSubmit('submitDraft')">保存草稿</a-button>
    <a-button :loading="loading['submitFormal']" :disabled="loading['submitFormal']" v-if="editModel != '2' && !onlySubmit" type="primary" class="button_right" @click="handleSubmit('submitFormal')">提交</a-button>
    <a-button v-if="onlySubmit" :loading="loading['submitValidate']" :disabled="loading['submitValidate']" type="primary" class="button_right" @click="handleValidate">提交</a-button>
    <a-button type="primary" @click="$close">关闭</a-button>
  </div>
</template>

<script>
import { print } from '@/api/quality/quality' // api
import BasePrintButton from '@/components/BasePrintButton' // 打印按钮

export default {
  name: 'a' + Date.now(),
  components: {
    BasePrintButton
  },
  props: {
    // 请求加载框
    needPrint: {
      type: Boolean,
      default: false
    },
    loading: {
      type: Object,
      default: () => ({ 'submitDraft': false, 'submitFormal': false, submitValidate: false })
    },
    // 操作类型：0 新增，1 编辑，2 查看，3 验证
    editModel: {
      type: [String, Number],
      default: () => '0'
    },
    // 只有一共提交按钮
    onlySubmit: {
      type: Boolean,
      default: false
    },
    templateCode: {
      type: String,
      default: ''
    },
    id: {
      type: String,
      default: ''
    },
    // 请求api
    api: {
      type: Object,
      default: () => null
    }
  },
  data() {
    return {
      statusCode: '' // 审批状态
    }
  },
  methods: {
    /**
     * @description: 获取打印内容
     * @return {*}
     */
    getPritContent() {
      return this.api?.primaryPrint({id: this.id, templateCode: this.templateCode}).then((res) => {
        if (res.data.content) {
          return res.data.content
        }
      })
    },
    /**
     * @description: 保存草稿或提交
     * @param {*} status：SUBMITTED：提交；DRAFT：保存草稿
     * @return {*}
     */
    handleSubmit(status) {
      // 提交校验表单
      if (status === 'submitFormal') {
        this.$emit('submitFormal')
      } else {
        // 保存只校验受检单位
        this.$emit('submitDraft')
      }
    },
    handleValidate() {
      this.$emit('submitValidate')
    }
  }
}
</script>